<template>
	<view class="">


		<uni-card>
			<template v-slot:title>
				<view class="m-l-10">
					<uni-row class="banmi_flex a-c p-t-20 m-l-20">
						<view class="banmi_flex" style="width: 120px;">
							<uni-easyinput v-model="uid" placeholder="请输入用户id">
							</uni-easyinput>
						</view>
						<view class="button_space m-l-10">
							<button @click="on_list" type="primary" size="mini">查询</button>
							<button @click="on_add" class="m-l-10" type="primary" size="mini">添加</button>
							<button @click="on_cha_a" type="warn" size="mini" class="m-l-10">重置</button>
						</view>

					</uni-row>
				</view>
			</template>
			<uni-table   border stripe :type="'2'"
				@selection-change="selectionData">
				<uni-tr>
					<uni-th align="center">id</uni-th>

					<uni-th align="center">名称</uni-th>
					<uni-th align="center">图片</uni-th>

					<uni-th align="center">标签</uni-th>
					<uni-th align="center">添加时间</uni-th>




					<uni-th align="center">uid</uni-th>
					<uni-th align="center">ip</uni-th>
					<uni-th align="center">状态</uni-th>



					<uni-th align="center">管理</uni-th>
				</uni-tr>

				<uni-tr v-for="(vo,index) in list" :key="index">

					<uni-td align="center">
						<view>{{vo.id}}</view>
					</uni-td>

					<uni-td align="center">
						<view>{{vo.shop_name}}</view>
					</uni-td>
					<uni-td align="center">
						<view>
							<image class="b_y" :src="vo.shop_img|getImg" style="width: 80px;height: 80px;" mode="">
							</image>
						</view>
					</uni-td>

					<uni-td align="center">
						<view>{{vo.shop_tag}}</view>
					</uni-td>




					<uni-td align="center">
						<view>{{vo.creation_time|getTime}}</view>
					</uni-td>


					<uni-td align="center">
						<view>{{vo.uid}}</view>
					</uni-td>
					<uni-td align="center">
						<view>{{vo.creation_ip}}</view>
					</uni-td>



					<uni-td align="center" :class="vo.status==1 ? 'feng' : 'aa'">

						{{vo.status_name}}<text v-if="vo.status==0">-{{vo.refuse_text}}</text>

					</uni-td>
					<uni-td align="center">
						<view class="t-c" v-if="vo.status==1||vo.status==0">
							<button @click="on_adopt(index)" type="primary" size="mini"
								style="background-color: #32CD32;width: 100px;">通过</button>
						</view>
						<view class="t-c" v-if="vo.status==1">
							<button @click="on_jujue(index,1)" style="width: 100px;" type="primary"
								size="mini">拒绝</button>
						</view>
						<view class="t-c">
							<button @click="on_edit(index)" style="width: 100px;" type="primary" size="mini">
								编辑
							</button>
						</view>


						<view class="t-c">
							<button @click="on_del(index)" style="background-color: #D3D3D3;width: 100px;"
								type="primary" size="mini">删除</button>
						</view>


					</uni-td>
				</uni-tr>
			</uni-table>
			<template v-slot:actions>
			 
					<uni-pagination @change="getPage" show-icon="true" :total="total" current="1"
						style="float: left;margin-bottom: 10px;"></uni-pagination>
			 
			</template>
		</uni-card>




		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-beizhu cancelText="取消" confirmText="确认" lei="0" :name="name" :keya="keya" @confirm="onxiugai">
			</uni-popup-beizhu>
		</uni-popup>

		<edit v-if="is_edit" :id="id" ref="component_edit" @confirm="confirm_edit" @close="is_edit=false">
		</edit>

	</view>
</template>

<script>
	import edit from './edit_shop.vue';
	export default {
		components: {
			edit
		},
		data() {
			return {
				list: [],
				last_page: 0,
				total: 0,
				page: 1,
				name: '',
				keya: '',
				uid: '',
				tel: '',
				is_edit: false,
				status_list: {
					"-1": "删除",
					"0": "已拒绝",
					"1": "待审核",
					"2": "正常"
				},
				id: 0

			}
		},
		onLoad(on) {
			this.init();
		},
		methods: {

			on_edit(index) {
				this.id = this.list[index]['id'];

				this.is_edit = true;

			},
			on_add() {
				this.id = 0;

				this.is_edit = true;
			},
			confirm_edit() {
				if (this.id == 0) {
					this.page = 1;
				}
				this.init();
				this.is_edit = false;
			},




			getPage(id) {

				this.page = id.current;
				this.init()
			},
			on_del(index) {
				var that = this;
				var id = this.list[index]['id'];
				uni.showModal({
					title: '提示',
					content: '确认删除商家吗？',
					success: function(res) {
						if (res.confirm) {
							that.ajax_del(id, index);
						}
					}
				});

			},
			on_top(index) {
				var that = this;
				var sort = 0;
				if (that.list[index]['sort'] == 0) {
					var sort = 1;
				}

				var id = that.list[index]['id'];

				let requestParams = {
					sort: sort,
					id: id,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/updates_zd_top', requestParams).then(ret => {
					var find = ret.data;
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					that.list[index]['sort'] = sort;
					this.init()
				})



			},
			ajax_del(id, index) {
				var that = this;
				this.id = that.list[index]['id'];
				let requestParams = {
					id: this.id,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/updates_scsj', requestParams).then(ret => {
					var find = ret.data;
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					})
					that.list = that.list.filter(t => t.id != id);
				})

			},
			ajax_adopt(id, index) {
				var that = this;
				var id = that.list[index]['id'];

				let requestParams = {
					id: id,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/updates_shtg', requestParams).then(ret => {
					var find = ret.data;
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					that.list[index]['status'] = 2;
					that.list[index]['status_name'] = this.status_list[2];
				})



			},
			on_jujue(index) {
				var that = this;
				var id = this.list[index]['id'];
				this.l_index = index;
				//填写拒绝理由
				this.name = '请输入拒绝理由';
				this.keya = id;
				this.$refs.alertDialog.open()


			},
			onxiugai(val) {
				var index = this.l_index;
				var that = this;
				let requestParams = {
					id: this.keya,
					text: val
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/updates_jujue', requestParams).then(ret => {
					var find = ret.data;
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					that.list[index]['status'] = 0;
					that.list[index]['refuse_text'] = val;
					that.list[index]['status_name'] = this.status_list[0];
					that.$refs.alertDialog.close()
				})




			},


			on_adopt(index) {
				var that = this;
				var id = this.list[index]['id'];
				uni.showModal({
					title: '提示',
					content: '确认审核通过吗？',
					success: function(res) {
						if (res.confirm) {
							that.ajax_adopt(id, index);
						}
					}
				});

			},
			on_cha() {
				this.init();
			},
			on_cha_a() {
				this.uid = '';
				this.tel = '';
				this.init();
			},
			on_list(index) {
				var that = this;
		 
				var uid = that.uid;
				let requestParams = { 
					uid: uid,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/paginate_cxsj', requestParams).then(ret => {
			 
					var list = ret.data.list.list;
			 
					for (var i = 0; i < list.length; i++) {
				 
						list[i]['status_name'] = this.status_list[list[i]['status']]
					}
					this.list = list;
					this.total = ret.data.list.total;
				})



			},
			init() {
				var that = this;

				let requestParams = {
					page: this.page,
				};
				this.Http.post('banmichaoqiangbizhi/admin/Shoplist/paginate_sjlb', requestParams).then(ret => {
					var ret = ret;
					var list = ret.data.list.list;
					for (var i = 0; i < list.length; i++) {
				 
						list[i]['status_name'] = this.status_list[list[i]['status']]
					}

					this.list = list;
					this.total = ret.data.list.total;
				})


			},
			on_tab(index) {
				this.tabindex = index;
			},



		}
	}
</script>

<style>
	.feng {
		color: red;
	}
</style>